package com.nutshare.lt.table;

import com.nutshare.lt.Result;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class SelectedTableCellRenderer extends DefaultTableCellRenderer
{
    private static final Color DEFAULT = Color.WHITE;

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {

        JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        PopularTableModel model = (PopularTableModel) table.getModel();
        int realColumn = model.getRealColumn(column);

        if(realColumn>-1)
        {
            Result r = model.stat.results.get(model.stat.results.size() - realColumn -1);

            System.out.println(model.stat.results.size() + " " + column + " " + realColumn + " " + r);




            if((column+2)%3 != 0)
            {
                if(r.contains((Integer)value))
                {
                    label.setBackground(Color.YELLOW);
                    Font f = label.getFont();
                    label.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
                }
                else
                {
                    label.setBackground(DEFAULT);
                }
            }
            else
            {
                label.setBackground(DEFAULT);
            }

        }
        else
        {
            label.setBackground(DEFAULT);
        }

        // TreeMap<Integer, Integer> r = ((PopularTableModel)table.getModel()).getResultForRealColumnIndex(realColumn);




        return label;
    }
}
